<template>
  <md-nav-bar title="一键MV" hideLeft >
  </md-nav-bar>
  <view class="create-btn" @click="createMv">
    <view class="create-btn-inner">
      <text class="icon">+</text>
      <text class="text">一键合成mv</text>
    </view>

  </view>
  <view class="list-container">
    <text class="list-title">我的mv</text>
    <view class="list">
      <md-page-list ref="listRef" :api="api.Mv.page" @change="pageChange">
        <view class="list-item" v-for="item in list" :key="item.id" @click="showDetail(item.videoId)">
          <image :src="item.coverUrl || 'https://cdn.xmxiaomai.com/isong_static/music/music-default-avatar.png'" mode="aspectFill"></image>
          <view class="list-item-title">{{ item.musicName }}</view>
<!--          <view class="delete-btn" @click="deleteItem(item.videoId)">-->
<!--            <uni-icons type="trash" color="#c0c4cc" size="24"></uni-icons>-->
<!--          </view>-->
          <view class="status-tag">
            <text>{{ getStatusLabel(item.status) }}</text>
          </view>
        </view>
      </md-page-list>

    </view>
  </view>
  <bottom-tab-bar :current="3" />
</template>
<script lang="ts"  setup>
import {ref} from "vue";
import api from "@/api";
import type {Music} from "@/api/data";

const listRef = ref();
const list = ref([])
const pageChange = (_list) => {
  list.value = _list;
};

const deleteItem = (id: number) => {
  uni.showModal({
    title: '提示',
    content: '确定要删除这个MV吗？',
    success: async function (res) {
      if (res.confirm) {
        await api.Mv.delete(id)
        await uni.showToast({
          title: '删除成功',
          icon: 'success'
        });
        listRef.value.onRefresh()
      }
    }
  });
}

const getStatusLabel = (status: number) => {
  switch (status) {
    case 0:
      return '合成中';
    case 1:
      return '合成中';
    case 2:
      return '已完成';
    case 3:
      return '合成失败';
    case 4:
      return '合成失败';
  }
}

const createMv = () => {
  uni.navigateTo({
    url: '/pages/sub/mv/create'
  });
}

const showDetail = (id: number) => {
  uni.navigateTo({
    url: `/pages/sub/mv/detail?id=${id}`
  });
}
</script>
<style lang="scss" scoped>
.create-btn {
  background: #0b5e4a;
  color: #fff;
  margin: 40rpx;
  padding: 40rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 20rpx;

  .create-btn-inner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    .icon {
      font-size: 60rpx;

    }
  }
}

.list-container {

  .list-title {
    padding:0 40rpx 20rpx;
    font-size: 32rpx;
    font-weight: bold;
  }

  .list {
    padding: 0 20rpx;
  }

  .list-item {
    width: 33.33%;
    padding: 20rpx 20rpx 0;
    box-sizing: border-box;
    position: relative;
    display: inline-block;
    vertical-align: top;
  }

  .list-item image {
    width: 100%;
    height: 240rpx;
    border-radius: 10rpx;
  }

  .list-item video {
    width: 100%;
    height: 240rpx;
    border-radius: 10rpx;
  }


  .list-item-title {
    //display: block;
    //text-align: left;
    //margin-top: 10rpx;
    //font-size: 28rpx;
    //height: 56rpx;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-wrap: break-word;
    word-break: break-word;
    line-height: 1.4em;
    max-height: 2.8em;
    text-align: left;
    margin-top: 10rpx;
    font-size: 28rpx;
    min-height: 2em;
  }

  .delete-btn {
    position: absolute;
    top: 210rpx;
    right: 30rpx;
    width: 40rpx;
    height: 40rpx;
    //background-color: rgba(0, 0, 0, 0.5);
    //border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .delete-icon {
    color: white;
    font-size: 30rpx;
    font-weight: bold;
  }

  .status-tag {
    position: absolute;
    top: 210rpx;
    left: 30rpx;
    color: #434343;
    font-size: 24rpx;
    font-weight: bold;
    background-color: rgba(255, 255, 255, 0.5);
    padding: 5rpx 10rpx;
    border-radius: 10rpx;
  }
}

page {
  background: #000 !important;
}

</style>